<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<!-- 导入jquery核心类库 -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/default.css">	
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/jquery.ocupload-1.1.2.js"
	type="text/javascript"></script>
<script type="text/javascript">
	function doAdd(){
		//alert("增加...");
		$('#addFactoryWindow').window("open");
	}
	
	function doView(){
		alert("查看...");
	}
	
	function doDelete(){
		alert("删除...");
	}
	///修改
	function doEdit(){
		var rows = $("#grid").datagrid('getSelections');
		alert(rows.length);
		if(rows.length ==1){
			$("#editFactoryWindow").window('open');
			$("#editFactoryForm").form('load',rows[0]);
			
		}else{
			$.messager.alert("提示信息","请选择一位需要修改的企业信息！","warning")
		}
		
		
	}
	//工具栏
	var toolbar = [ {
		id : 'button-view',	
		text : '查询',
		iconCls : 'icon-search',
		handler : doView
	}, {
		id : 'button-add',
		text : '增加',
		iconCls : 'icon-add',
		handler : doAdd
	}, {
		id : 'button-Import',
		text : '导入',
		iconCls : 'icon-redo',
	},{
		id : 'button-edit',
		text : '修改',
		iconCls : 'icon-edit',
		handler : doEdit
	}];
	// 定义列
	var columns = [ [ {
		field : 'id',
		checkbox : true,
	},{
		field : 'nameFull',
		title : '全名',
		width : 200,
		align : 'center'
	}, {
		field : 'nameShort',
		title : '简称',
		width : 120,
		align : 'center'
	}, {
		field : 'address',
		title : '地址',
		width : 230,
		align : 'center',
	}, {
		field : 'phone',
		title : '电话',
		width : 120,
		align : 'center',
	}, {
		field : 'leader',
		title : '管理者',
		width : 120,
		align : 'center'
	}, {
		field : 'leaderPhone',
		title : '管理者电话',
		width : 120,
		align : 'center'
	} ] ];
	
	$(function(){
		// 先将body隐藏，再显示，不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		// 取派员信息表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : false,
			rownumbers : true,
			striped : true,
			pageList: [30,50,100],
			pagination : true,
			toolbar : toolbar,
			url : "/factoryPageQuery.action",
			idField : 'id',
			columns : columns,
			onDblClickRow : doDblClickRow
		});
		
		
		//添加上传
		$("#button-Import").upload({
			name:'myFile',
			action:'/factoryImport.action',
			onComplete: function(data) {
				$.messager.confirm('提示信息', '已经上传成功了是否跳转到列表页面?', function(r){
					if (r){  
						location.href="/base/qiye.action";
					} 
					});
				
			},
		});
		
		// 添加企业信息窗口
		$('#addFactoryWindow').window({
	        title: '添加企业信息',
	        width: 400,
	        modal: true,
	        shadow: true,
	        closed: true,
	        height: 350,
	        resizable:false
	    });
		
		// 修改企业信息窗口
		$('#editFactoryWindow').window({
	        title: '修改企业信息',
	        width: 400,
	        modal: true,
	        shadow: true,
	        closed: true,
	        height: 350,
	        resizable:false
	    });
		
	});

	function doDblClickRow(rowIndex, rowData){
		$("#editFactoryWindow").window('open');
		$("#editFactoryWindow").form('load',rowData);
	}
	//手机号码规则效验
	$(function(){
		var tel = /^1(3[0-9]|5[189]|8[6789])[0-9]{8}$/;
		$.extend($.fn.validatebox.defaults.rules, { 
				telephone: { 
					validator: function(value,param){ 
					return tel.test(value); 
					}, 
				message: '手机号码输入的格式不对！' 
					} 
			}); 
	});
	
	//添加企业信息
	$(function(){
		$("#saveFactoryInfo").click(function(){
			
			var vali = $("#addFactoryForm").form('validate');
			if(vali){
				$("#addFactoryForm").submit();
				$("#addFactoryWindow").window('close');
			}else{
				$.messager.alert('提示信息','您填写的信息不完整,麻烦请认真填写！','error');  
			}
			
		});
		
	});
</script>	
</head>
<body class="easyui-layout" style="visibility:hidden;">
	<div region="center" border="false">
    	<table id="grid"></table>
	</div>
	<!-- 企业信息添加 -->
	<div class="easyui-window" title="对企业信息进行添加" id="addFactoryWindow" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:200px">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="saveFactoryInfo" icon="icon-save" href="#" class="easyui-linkbutton" plain="true" >保存</a>
				<script type="text/javascript">
				
				</script>
			</div>
		</div>
		
		<div region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="addFactoryForm" action="/addFactoryInfo.action" method="post">
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="2">添加合作企业</td>
					</tr>
					<tr>
						<td>全名</td>
						<td><input type="text" name="nameFull" class="easyui-validatebox" required="true"/></td>
					</tr>
					<tr>
						<td>简称</td>
						<td><input type="text" name="nameShort" class="easyui-validatebox" required="true"/></td>
					</tr>
					<tr>
						<td>地址</td>
						<td><input type="text" name="address" class="easyui-validatebox" required="true"/></td>
					</tr>
					<tr>
						<td>电话</td>
						<td><input type="text" name="phone" class="easyui-validatebox" required="true" validType="telephone"/></td>
					</tr>
					<tr>
						<td>管理者</td>
						<td><input type="text" name="leader" class="easyui-validatebox" required="true"/></td>
					</tr>
					<tr>
						<td>管理者电话</td>
						<td><input type="text" name="leaderPhone" class="easyui-validatebox" required="true" validType="telephone"/></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	<!-- 修改企业信息 -->
	<div class="easyui-window" title="对企业信息进行修改" id="editFactoryWindow" collapsible="false" minimizable="false" maximizable="false" style="top:20px;left:200px">
		<div region="north" style="height:31px;overflow:hidden;" split="false" border="false" >
			<div class="datagrid-toolbar">
				<a id="editFactoryInfo" icon="icon-edit" href="#" class="easyui-linkbutton" plain="true" >保存</a>
				<script type="text/javascript">
					$(function(){
						$("#editFactoryInfo").click(function(){
							var vali = $("#editFactoryForm").form('validate');
							if(vali){
								$("#editFactoryForm").submit();
								$("#editFactoryWindow").window('close');
								
							}else{
								$.messager.alert('提示信息','您填写的信息不不完善','warning');  
							}
							
						})
					})
				</script>
			</div>
		</div>
		
		<div region="center" style="overflow:auto;padding:5px;" border="false">
			<form id="editFactoryForm" action="/editFactoryInfo.action" method="post">
				<input type="hidden" name="id">
				<table class="table-edit" width="80%" align="center">
					<tr class="title">
						<td colspan="2">添加合作企业</td>
					</tr>
					<tr>
						<td>全名</td>
						<td><input type="text" name="nameFull" class="easyui-validatebox" required="true"/></td>
					</tr>
					<tr>
						<td>简称</td>
						<td><input type="text" name="nameShort" class="easyui-validatebox" required="true"/></td>
					</tr>
					<tr>
						<td>地址</td>
						<td><input type="text" name="address" class="easyui-validatebox" required="true"/></td>
					</tr>
					<tr>
						<td>电话</td>
						<td><input type="text" name="phone" class="easyui-validatebox" required="true" validType="telephone"/></td>
					</tr>
					<tr>
						<td>管理者</td>
						<td><input type="text" name="leader" class="easyui-validatebox" required="true"/></td>
					</tr>
					<tr>
						<td>管理者电话</td>
						<td><input type="text" name="leaderPhone" class="easyui-validatebox" required="true" validType="telephone"/></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>	